package com.godGuang.patient.controller;

import com.godGuang.common.core.domain.Result;
import com.godGuang.common.log.annotation.Log;
import com.godGuang.common.log.enums.BusinessType;
import com.godGuang.patient.service.WalletService;
import com.patient.domin.Account;
import com.patient.domin.Wallet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 钱包前端控制器
 */
@Slf4j
@RestController
@RequestMapping("/wallet")
@CrossOrigin(origins = "http://localhost")
public class WalletController {
    @Autowired
    private WalletService walletService;

    /**
     * @description: 创建钱包
     * @author: Lxk
     * @date: 2024/1/10 16:18
     * @param: [wallet]
     * @return: com.godGuang.common.core.domain.Result
     **/
    @PostMapping("/establishWallet")
    public Result establishWallet(@RequestBody Wallet wallet){
        return walletService.establishWallet(wallet);
    }

    /**
     * @description: 查询我的钱包
     * @author: Lxk
     * @date: 2024/1/10 19:04
     * @param: []
     * @return: com.godGuang.common.core.domain.Result
     **/
    @GetMapping("/walletList")
    public Result<Wallet> getWalletList(){
        Wallet walletList = walletService.getWalletList();
        return Result.success(walletList);
    }

    /**
     * @description: 钱包充值H币
     * @author: Lxk
     * @date: 2024/1/17 19:54
     * @param: [money]
     * @return: com.godGuang.common.core.domain.Result
     **/
    @GetMapping("/recharge/{money}")
    @Log(title = "钱包充值H币", businessType = BusinessType.INSERT)
    public Result recharge(@PathVariable("money") Integer money){
        if (null == money){
            throw new RuntimeException("充值金额不能为空!");
        }
        int recharge = walletService.recharge(money);
        return Result.success(recharge,"充值成功,请刷新查看详细金额");
    }

    /**
     * @description: 查询钱包记录列表
     * @author: Lxk
     * @date: 2024/1/18 15:25
     * @param: []
     * @return: com.godGuang.common.core.domain.Result<java.util.List<com.patient.domin.Account>>
     **/
    @PostMapping("/listAccount")
    public Result<List<Account>> listAccount(){
        log.info("查询钱包记录列表");
        List<Account> listResult = walletService.listAccount();
        return Result.success(listResult);
    }
}
